import request from "@/utils/request";
import SerialNumber from "./SerialNumber";

export default {
  getOrderList(serachModel, orderStatus) {
    // 判断查询
    if (
      serachModel.phone != null ||
      serachModel.orderNumber != null ||
      serachModel.userName != null ||
      serachModel.deliveryDate != null ||
      serachModel.endTime != null ||
      serachModel.createTime
    ) {
      serachModel.pageNo = 1;
    }

    return request({
      url: "/order/list",
      method: "get",
      params: {
        pageNo: serachModel.pageNo,
        pageSize: serachModel.pageSize,
        orderNumber: serachModel.orderNumber,
        phone: serachModel.phone,
        deliveryDate: serachModel.deliveryDate,
        orderByDesc: serachModel.orderByDesc,
        userName: serachModel.userName,
        endTime: serachModel.endTime,
        getReceiptDate: serachModel.getReceiptDate,
        orderStatus: orderStatus,
        createTime: serachModel.createTime,
      },
    });
  },

  getOrderById(id) {
    return request({
      url: `/order/${id}`,
      method: "get",
    });
  },

  addOrder(order) {
    // 处理订单的时间

    return request({
      url: "/order",
      method: "post",
      data: order,
    });
  },

  updateOrder(order, model) {
    return request({
      url: `/order`,
      method: "put",
      data: order,
      params: { model: model },
    });
  },

  saveOrder(order, model) {
    if (order.id == null && order.id == undefined) {
      return this.addOrder(order);
    }
    return this.updateOrder(order, model);
  },

  deleteOrderById(id) {
    return request({
      url: `/order/${id}`,
      method: "delete",
    });
  },

  deleteOrderByIds(orders) {
    return request({
      url: `/order/ids`,
      method: "delete",
      data: orders,
    });
  },

  setOrderStatusByIds(ids, statusCode) {
    return request({
      url: "/order/ids",
      method: "put",
      data: ids,
      params: { statusCode: statusCode },
    });
  },

  updateOrderStatus(id, UpdateModelAndStatus) {
    return request({
      url: `/order/updateStatus/${id}`,
      method: "put",
      data: UpdateModelAndStatus,
    });
  },

  addOders(orders) {
    return request({
      url: `/order/addOrders`,
      method: "post",
      data: orders,
    });
  },

  // 发货
  sendProduct(product) {
    return request({
      url: `/order/sendProduct`,
      method: "post",
      data: product,
    });
  },

  // 更新库存状态
  updateStockStatus(ids, statusCode) {
    return request({
      url: `/order/updateStockStatus`,
      method: "put",
      data: ids,
      params: { statusCode: statusCode },
    });
  },

  // 更新寄出单号
  updateTrackingNumber(order) {
    return request({
      url: `/order/updateTrackingNumber/${order.id}`,
      method: "put",
      data: {
        trackingNumber: order.trackingNumber,
      },
    });
  },

  // 查寄回
  updateReceiptNumber(order) {
    return request({
      url: `/order/updateReceiptNumber/${order.id}`,
      method: "put",
      data: order,
    });
  },

  // 更新状态为已寄回
  updateSendBackStatus(id) {
    return request({
      url: `/order/receiptStatus/${id}`,
      method: "put",
    });
  },

  // 查寄回查询订单
  getSendBackOrderList(sendBackModel) {
    // 判断查询
    if (sendBackModel.phone != null || sendBackModel.username != null) {
      sendBackModel.pageNo = 1;
    }

    return request({
      url: "/order/getSendBackOrderList",
      method: "get",
      params: {
        pageNo: sendBackModel.pageNo,
        pageSize: sendBackModel.pageSize,
        phone: sendBackModel.phone,
        orderNumber: sendBackModel.orderNumber,
        username: sendBackModel.username,
      },
    });
  },

  // 查寄回查询订单
  getSendBackOrder() {
    return request({
      url: "/order/getSendBackOrder",
      method: "get",
    });
  },

  // 查需要售后订单
  receiveOrder(receiveData) {
    return request({
      url: "/order/receiveOrder",
      method: "post",
      data: receiveData,
    });
  },

  // 处理售后订单
  afterSaleOrderIsOk(id) {
    return request({
      url: `/order/isOk/${id}`,
      method: "post",
    });
  },

  // 签收订单
  getNeedAfterSaleOrder(sendBackModel) {
    return request({
      url: "/order/getNeedAfterSaleOrder",
      method: "get",
      params: {
        pageNo: sendBackModel.pageNo,
        pageSize: sendBackModel.pageSize,
        phone: sendBackModel.phone,
        orderNumber: sendBackModel.orderNumber,
      },
    });
  },

  // 首页信息
  dashboardData() {
    return request({
      url: `/order/getDashboardData`,
      method: "get",
    });
  },

  // 订单导出
  exportOrders(data) {
    window.open(
      this.DownloadOrder +
        `?startTime=${data.startTime}&endTime=${data.endTime}&orderStatus=${data.orderStatus}`
    );
  },
  // 批量签收订单
  receiveOrders(receiveOrders) {
    return request({
      url: `/order/receiveOrders`,
      method: "post",
      data: receiveOrders,
    });
  },

  // DownlaodSendOrder: "http://localhost:9999/sys/order/exportSendOrder",
  DownlaodSendOrder: "http://154.8.182.144:9999/sys/order/exportSendOrder",
  // DownlaodSendOrder: "http://www.quzhi.org.cn:9999/sys/order/exportSendOrder",

  // DownlaodSerialNumberOrder:
  // "http://localhost:9999/sys/order/exportSerialNumber",
  DownlaodSerialNumberOrder:
    "http://154.8.182.144:9999/sys/order/exportSerialNumber",
  // DownlaodSerialNumberOrder:
  //   "http://www.quzhi.org.cn:9999/sys/order/exportSerialNumber",

  // DownloadOrder: "http://localhost:9999/sys/order/export",
  DownloadOrder: "http://154.8.182.144:9999/sys/order/export",
  // DownloadOrder: "http://www.quzhi.org.cn:9999/sys/order/export",

  // importOrder: "http://localhost:9999/sys/order/import",
  importOrder: "http://154.8.182.144:9999/sys/order/import",
  // importOrder: "http://www.quzhi.org.cn:9999/sys/order/import",
};
